<?php
	$isImageRequired = cr('ListingConfig.listing_image_required');
	$form->create("Listing");
	//this will set empty options for all fields.
	$form->defaultEmpty = __("-Select-");
	$tagData = '';
	if(empty($this->data))
	{
			$tagData = '';
	}elseif(isset($this->data['Tag']['tag']))
	{
			$tagData = $this->data['Tag']['tag'];
	}
?>		
	
	<?php		
		echo $this->element('listing_add_form_fields',array('listingDefaultFields'=>$listingDefaultFields));
		if($isTagEnabled == true)
		{
			echo $form->input('Tag.tag',array('label'=>'Tags','value'=>$tagData));
		}
		if(cr("ListingConfig.add_review_with_listing"))
		{
			echo $form->input("add_review",array("type"=>"checkbox","label"=>__("Write a review "),'div'=>"input checkbox add_review_link"));
			$showReviewForm = false;
			if(isset($this->data['Listing']['add_review']) && $this->data['Listing']['add_review']==1)
			{
				$showReviewForm = true;
			}
			?>
			<div id="review_form_fields_div" <?php echo ((!$showReviewForm)?"style='display: none;'":""); ?>>
			<?php 
			$ReviewModel = cri("Review");
			$reviewFields = $ReviewModel->getFields("group","add");
			if(!empty($reviewFields))
			{
				$form->create("Review");
				?>
				<div>
					<fieldset>
						<legend><?php echo __("Review");?></legend>
						<?php 
						foreach($reviewFields as $reviewField)
						{
							echo $form->input("Review.".$reviewField);
						}
						?>
					</fieldset>
				</div>	
				<?php
			}
			?>
			</div>		
			<?php 
		}
		//#5980
		$form->create("Listing");
		echo $form->input("asset_inputs");
	?>
<script type='text/javascript'>
$(document).ready(function()
{
	var isImageRequired = <?php echo $javascript->object($isImageRequired)?>;
	
	if(isImageRequired)
	{
		$('#ListingAsset0Name').parent('div').addClass('required');
	}
});

$("#ListingAddReview").change(function(){
	if($(this).attr("checked"))
	{
		$("#review_form_fields_div").show();
	} else {
		$("#review_form_fields_div").hide();
	}
});

</script>